<%--
  Created by IntelliJ IDEA.
  User: chensir
  Date: 2020/12/7
  Time: 15:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>

<head>
    <title>欢迎登录在线选课系统</title>
    <link rel="stylesheet" type="text/css" href="css/index.css">
</head>

<body>
<div class="contain">
    <div class="loginHead"><span>欢迎登录在线选课系统</span></div>

    <div class="loginBody">
        <div class="logo">

        </div>
        <div class="login">
            <form action="loginServlet" method="post" id="loginForm" name="loginFrom">
                <div class="loginBox">
                    <div class="userName">用户名：<label><input type="text" id="userName" name="userName"
                                                            placeholder="请输入学号或教职工号"></label></div>
                    <div class="Pwd">密　码：<label><input type="password" id="Pwd" name="Pwd" placeholder="请输入密码"></label>
                    </div>
                    <div class="role">您是　<select name="role" id="role">
                        <option value="0">学生</option>
                        <option value="1">老师</option>
                    </select>
                    </div>

                    <div class="btn">
                        <input type="submit" id="submit" value="登录">　　<input type="reset" id="reset" value="重置">
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="loginFoot">版权所有©XX科技有限公司</div>
</div>


<%
    if (request.getAttribute("message") != null) {
%>
<script>
    alert("登陆失败，请核对用户名，密码和您的角色");
    window.location.href =
    <%= request.getContextPath() + "/"%>
</script>
<%}%>

<%
    if (request.getAttribute("outMessage") != null) {
%>
<script>
    alert("退出成功");
    window.location.href =
    <%= request.getContextPath() + "/"%>
</script>
<%}%>


<script>
    let userName = document.getElementById("userName")
    let pwd = document.getElementById("Pwd")
    let submit = document.getElementById("submit")
    let form = document.getElementById("loginForm")
    let role = document.getElementById('role')

    submit.addEventListener("click", (e) => {
        if (form.userName.value === '') {
            alert("请输入用户帐号!");
            form.userName.focus();
            if (e && e.preventDefault)
                e.preventDefault();
            else
                window.event.returnValue = false;
        } else if (form.Pwd.value === '') {
            alert("请输入密码!");
            form.Pwd.focus();
            if (e && e.preventDefault)
                e.preventDefault();
            else
                window.event.returnValue = false;
        }
    })
</script>
</body>
</html>
